package com.xiaoxi.open.design.creation.builderpattern.builder;

import com.xiaoxi.open.design.creation.builderpattern.domain.MyDomain;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author xiaoxi
 * @ProjectName creation_pattern
 * @PackageName com.xiaoxi.open.design.creation.builderpattern.builder
 * @ClassName HtmlBuilder
 * @Description TODO
 * @Date 2024/5/14 10:50
 * @Version 1.0
 */
@Service
@Slf4j
public class HtmlBuilder implements IBuilder {
    @Override
    public void open() {
        System.out.println("<html><head><title>HTML生成器</title></head><body>");
    }

    @Override
    public void buildTitle(String str) {
        System.out.println("<h1>" + str + "</h1>");
    }

    @Override
    public void buildString(String str) {
        System.out.println(str + "<ul>");
    }

    @Override
    public void buildTray(List<MyDomain> myDomainList) {
        for (MyDomain myDomain : myDomainList) {
            System.out.println("<li><a href=\"" + myDomain.getUrl() + "\">" + myDomain.getContent() + "</a></li>");
        }
        System.out.println("</ul>");
    }

    @Override
    public void close() {
        System.out.println("</body></html>");
    }
}
